<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      position: relative;
      margin: 50px auto;
      width: 512px;
      height: 400px;
      border: 1px solid #000;
      overflow: hidden;
    }

    .box>img {
      position: absolute;
      top: 0;
      left: 0;
    }

    .box>#up {
      position: absolute;
      left: 0;
      top: 0;
      height: 200px;
      width: 100%;
    }

    .box>#down {
      position: absolute;
      left: 0;
      bottom: 0;
      height: 200px;
      width: 100%;
    }
  </style>
</head>

<body>
  <div class="box">
    <img src="./mi.png" alt="">
    <span id="up"></span>
    <span id="down"></span>
  </div>
</body>
<script>
  function $(selected) {
    return document.querySelector(selected)
  }
  var moveVal = 0;
  var tmer = null;
  $('#up').onmouseover = function () {
    clearInterval(tmer)
    tmer = setInterval(() => {
      moveVal -= 3
      if (moveVal <= -1047) {
        clearInterval(tmer)
      } else {
        $('img').style.top = moveVal + 'px'
      }
    }, 30);
  }

  $('#down').onmouseover = function () {
    clearInterval(tmer)
    tmer = setInterval(() => {
      moveVal += 3
      if (moveVal <= 0) {
        $('img').style.top = moveVal + 'px'
      } else {
        clearInterval(tmer)
      }
    }, 30);

  }
  $('.box').onmouseout = function () {
    clearInterval(tmer)
  }
</script>

</html>